﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace CustomControl
{
    public class LinePanel: Panel
    {
        public bool LineTop { get; set; }
        public bool LineLeft { get; set; }
        public bool LineRight { get; set; }
        public bool LineBottom { get; set; }

        public Color LineTop1Color
        {
            get;
            set;
        }

        public Color LineTop2Color
        {
            get;
            set;
        }

        public Color LineLeft1Color
        {
            get;
            set;
        }

        public Color LineLeft2Color
        {
            get;
            set;
        }

        public Color LineRight1Color
        {
            get;
            set;
        }

        public Color LineRight2Color
        {
            get;
            set;
        }

        public Color LineBottom1Color
        {
            get;
            set;
        }

        public Color LineBottom2Color
        {
            get;
            set;
        }

        public LinePanel()
        {
            LineTop1Color = SystemColors.ButtonShadow;
            LineTop2Color = SystemColors.Window;
            LineLeft1Color = SystemColors.ButtonShadow;
            LineLeft2Color = SystemColors.Window;
            LineRight1Color = SystemColors.ButtonShadow;
            LineRight2Color = SystemColors.Window;
            LineBottom1Color = SystemColors.ButtonShadow;
            LineBottom2Color = SystemColors.Window;

            LineTop = true;
            LineLeft = false;
            LineRight = false;
            LineBottom = false;

            this.Dock = DockStyle.Bottom;
            
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            DrawLine();
        }

        void DrawLine()
        {

            Pen myPen1 = null;
            Pen myPen2 = null;
            Graphics panelGraphics = this.CreateGraphics();

            if (LineTop)
            {
                myPen1 = new Pen(LineTop1Color);
                myPen2 = new Pen(LineTop2Color);
                panelGraphics.DrawLine(myPen1, 0, 0, this.Width, 0);
                panelGraphics.DrawLine(myPen2, 0, 1, this.Width, 1);
            }

            if (LineLeft)
            {
                myPen1 = new Pen(LineLeft1Color);
                myPen2 = new Pen(LineLeft2Color);
                panelGraphics.DrawLine(myPen1, 0, 0, 0, this.Height);
                panelGraphics.DrawLine(myPen2, 1, 0, 1, this.Height);            
            }

            if (LineRight)
            {
                myPen1 = new Pen(LineRight1Color);
                myPen2 = new Pen(LineRight2Color);
                panelGraphics.DrawLine(myPen2, this.Width - 1, 0, this.Width - 1, this.Height);
                panelGraphics.DrawLine(myPen1, this.Width - 2, 0, this.Width - 2, this.Height);
            }

            if (LineBottom)
            {
                myPen1 = new Pen(LineBottom1Color);
                myPen2 = new Pen(LineBottom2Color);
                panelGraphics.DrawLine(myPen1, 0, this.Height - 2, this.Width, this.Height - 2);
                panelGraphics.DrawLine(myPen2, 0, this.Height - 1, this.Width, this.Height - 1);
            }
            myPen1.Dispose();
            myPen2.Dispose();

            panelGraphics.Dispose();

        
        }
    }
}
